newfileout = 0;
newdirout = 0;
uploadout = 0;
editorout = 0;

function ajaxfade(script, outputdiv, num)
{
	newfileout = 0;
	newdirout = 0;
	uploadout = 0;
	editorout = 0;
		
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow');
	}
		
    var hoehe = $("#slider").height();
	if(hoehe == 0)
	{
		$(outputdiv).html("<center><div style=\"padding:15px\"><img src=\"images/ajax-loader.gif\" style=\"display: block; padding-bottom: 10px\" />Lade...</div></center>");
	}
	
	if (num != null)
	{
		$("#loader_" + num).fadeIn("fast");
	}
	else
	{
		$("#loader").fadeIn("fast");
	}

	$.get(script, function(data)
	{
	    $(outputdiv).html(data);
		$(outputdiv).hide();
		$(outputdiv).fadeToggle("");
		$("#ajaxdiv").css("height", "auto");
    });   
}

function newdirectory(curdir)
{	
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(uploadout == 1 || newfileout == 1 || editorout == 1)
			{
				$("#bottomLoader").fadeIn("fast");
				$.get('ajax/newdirectory.php?dir='+curdir+'', function(data)
				{
					n.html(data);
	    			n.animate({top: '0px'}, 'slow');
	    			n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    				$("#bottomLoader").fadeOut("fast");
	    		});
		    	uploadout = 0;
		    	newfileout = 0;	
		    	editorout = 0;
		    	newdirout = 1;	
			}
			else
			{
				newdirout = 0;
			}
		});
	}
	else
	{
		$("#bottomLoader").fadeIn("fast");
		$.get('ajax/newdirectory.php?dir='+curdir+'', function(data)
		{
			n.html(data);
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    		$("#bottomLoader").fadeOut("fast");
    	});
    	newdirout = 1;		
	}
}

function newfile(curdir)
{	
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(uploadout == 1 || newdirout == 1 || editorout == 1)
			{
				$("#bottomLoader").fadeIn("fast");
				$.get('ajax/newfile.php?dir='+curdir+'', function(data)
				{
					n.html(data);
		    		n.animate({top: '0px'}, 'slow');
		    		n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    				$("#bottomLoader").fadeOut("fast");
		    	});
		    	uploadout = 0;
		    	newdirout = 0;
		    	editorout = 0;
		    	newfileout = 1;		
			}
			else
			{
				newfileout = 0;
			}
		});
	}
	else
	{
		$("#bottomLoader").fadeIn("fast");
		$.get('ajax/newfile.php?dir='+curdir+'', function(data)
		{
			n.html(data);
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    		$("#bottomLoader").fadeOut("fast");
    	});
    	newfileout = 1;		
	}
}

function settings()
{	
	var n = $("#settings");
	
	if (n.css('top') == "0px")
	{
		var animate = n.outerHeight() + 10 + "px";
		n.animate({top: '-' + animate}, 'slow');
	}
	else
	{
		$.get('ajax/settings.php', function(data)
		{
			n.html(data);
	    	n.animate({top: '0px'}, 'slow');
	    });
	}
}

function rename(old, curdir, type, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader_" + num).fadeToggle("fast");
		m.css('display', 'block');
	    
	    $.get('ajax/rename.php?type=' + type + '&curdir=' + curdir + '&old=' + old + '', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader_" + num).fadeToggle("fast");
		});
	}
}

function edit(editfile, num, curdir)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);
	
	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader_" + num).fadeToggle("fast");
		m.css('display', 'block');
	    
	    $.get('ajax/edit.php?dir='+curdir+'&file='+editfile+'', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow', function()
			{
				$('html, body').animate({scrollTop: n.offset().top - 24}, 'slow');
			});
			$("#loader_" + num).fadeToggle("fast");
		});
	}
}

function deletest(todelete, curdir, type, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader_" + num).fadeToggle("fast");
	    m.css('display', 'block');
	    $.get('ajax/delete.php?type='+type+'&delete='+todelete+'&dir='+curdir+'', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader_" + num).fadeToggle("fast");
		});
	}
	m.css('display', 'block');
}

function chmod(chmod, tochmod, curdir, num)
{
	var m = $("#tools_" + num);
	var n = $("#tool_" + num);

	if (n.html() != '')
	{
		n.animate({top: '-' + n.outerHeight() + 'px'}, 'slow');
		n.parent().animate({height: '0px'}, 'slow');
		m.slideUp('slow', function(){
			n.html('');
			n.css('top', '0px');
		});
	}
	else
	{
		$("#loader_" + num).fadeToggle("fast");
	    m.css('display', 'block');
	    $.get('ajax/chmod.php?num='+num+'&chmod=' + chmod + '&tochmod=' + tochmod + '&dir=' + curdir + '', function(data)
		{
			n.html(data);
			
			m.slideDown('slow');
	    
	    	n.css('top', '-' + n.outerHeight() + 'px');
	    	n.parent().css('height', '0px');
			n.animate({top: '0px'}, 'slow');
			
			n.parent().animate({height: n.outerHeight() + 'px'}, 'slow');
			$("#loader_" + num).fadeToggle("fast");
			chmodcheckbox();
		});
	}
	m.css('display', 'block');
}

function upload(curdir)
{
	var n = $("#bottomAction");
	
	if (n.css('top') == "0px")
	{
		n.animate({
			top: '-' + n.outerHeight() + 'px',
			width: '500px'
		}, 'slow');
		n.parent().slideUp('slow', function()
		{
			if(newfileout == 1 || newdirout == 1 || editorout == 1)
			{
				$("#bottomLoader").fadeIn("fast");
				$.get('ajax/upload.php?dir='+curdir+'', function(data)
				{
					n.html(data);
		    		n.animate({top: '0px'}, 'slow');
		    		n.parent().slideDown('slow');
    				$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    				$("#bottomLoader").fadeOut("fast");
		    	});
		    	newdirout = 0;
		    	newfileout = 0;	
		    	editorout = 0;	
		    	uploadout = 1;
			}
			else
			{
				uploadout = 0;
			}
		});
	}
	else
	{
		$("#bottomLoader").fadeIn("fast");
		$.get('ajax/upload.php?dir='+curdir+'', function(data)
		{
			n.html(data);
    		n.animate({top: '0px'}, 'slow');
    		n.parent().slideDown('slow');
    		$('html, body').animate({scrollTop: $('html').height()}, 'slow');
    		$("#bottomLoader").fadeOut("fast");
    	});
    	uploadout = 1;
	}
}

function closeNotification()
{
	$(".notification").fadeOut("slow");
}

function savefile(filetosave, curdir)
{
	$("#loader_" + num).fadeToggle("fast");
	var code = $('#code').val();
	
	$.post( 
		'../ajax/showdirectory.php?dir='+curdir+'', 
		{ 
			newfilecontent: code, 
			filetosave   : filetosave
		},
		function(data)
		{
			$('#slider').html(data);
			$('#slider').hide();
			$('#slider').fadeToggle("");
			$("#ajaxdiv").css("height", "auto");
		}
	);
}

function getfile(file)
{	
	var n = $("#bottomAction");	
		$.ajax({
			type: "POST",
			url: "ajax/download.php", 
			data: "dir=" + file,
			cache: false,
			success: function(data)
			{}
    	});
}

function Rechte(num)
{
	document.getElementsByName('chmodform_' + num)[0].newchmod.value=""+
	  Oct(document.getElementsByName('chmodform_' + num)[0].or.checked, document.getElementsByName('chmodform_' + num)[0].ow.checked, document.getElementsByName('chmodform_' + num)[0].ox.checked)+
	  Oct(document.getElementsByName('chmodform_' + num)[0].gr.checked, document.getElementsByName('chmodform_' + num)[0].gw.checked, document.getElementsByName('chmodform_' + num)[0].gx.checked)+
	  Oct(document.getElementsByName('chmodform_' + num)[0].ar.checked, document.getElementsByName('chmodform_' + num)[0].aw.checked, document.getElementsByName('chmodform_' + num)[0].ax.checked);
}

function chmodcheckbox(num)
{
	var chmodvalue = document.getElementsByName('chmodform_' + num)[0].newchmod.value;
	
	var ownerbin = parseInt(chmodvalue.charAt(0)).toString(2);
	var groupbin = parseInt(chmodvalue.charAt(1)).toString(2);
	var otherbin = parseInt(chmodvalue.charAt(2)).toString(2);

	while(ownerbin.length<3)
		ownerbin="0"+ownerbin; 
	while(groupbin.length<3)
		groupbin="0"+groupbin;
	while(otherbin.length<3)
		otherbin="0"+otherbin;

	document.getElementsByName('chmodform_' + num)[0].or.checked = parseInt(ownerbin.charAt(0)); 
	document.getElementsByName('chmodform_' + num)[0].gr.checked = parseInt(groupbin.charAt(0));
	document.getElementsByName('chmodform_' + num)[0].ar.checked = parseInt(otherbin.charAt(0));
	document.getElementsByName('chmodform_' + num)[0].ow.checked = parseInt(ownerbin.charAt(1)); 
	document.getElementsByName('chmodform_' + num)[0].gw.checked = parseInt(groupbin.charAt(1));
	document.getElementsByName('chmodform_' + num)[0].aw.checked = parseInt(otherbin.charAt(1));
	document.getElementsByName('chmodform_' + num)[0].ox.checked = parseInt(ownerbin.charAt(2)); 
	document.getElementsByName('chmodform_' + num)[0].gx.checked = parseInt(groupbin.charAt(2));
	document.getElementsByName('chmodform_' + num)[0].ax.checked = parseInt(otherbin.charAt(2));
}